<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="工程编号" prop="jobNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.jobNumber" placeholder="请填写工程编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="合同金额" prop="contractAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.contractAmount" placeholder="请填写合同金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单项名称" prop="singleName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.singleName" placeholder="请填写单项名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="结算性质" prop="settlementProperties"
                :rules="[
                 ]">
                <el-select v-model="inputForm.settlementProperties" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('settlement_properties')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预计开工时间" prop="onstreamTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.onstreamTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预计完工时间" prop="completionTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.completionTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程施工性质" prop="natureEngineeringConstruction"
                :rules="[
                 ]">
                <el-select v-model="inputForm.natureEngineeringConstruction" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('nature_engineering_construction')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程来源性质" prop="natureEngineeringSource"
                :rules="[
                 ]">
              <el-input v-model="inputForm.natureEngineeringSource" placeholder="请填写工程来源性质"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程大项" prop="singleProject"
                :rules="[
                 ]">
              <el-input v-model="inputForm.singleProject" placeholder="请填写工程大项"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="管理费类别" prop="managementFeeCategory"
                :rules="[
                 ]">
              <el-input v-model="inputForm.managementFeeCategory" placeholder="请填写管理费类别"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程类型" prop="projectType"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectType" placeholder="请填写工程类型"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="专业id" prop="major.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择专业id"
            labelName = 'majorName'
            labelValue = 'id'
            :value = "inputForm.major.id"
            :limit="1"
            @getValue='(value) => {inputForm.major.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'majorName',
              label: '专业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'majorName',
              label: '专业名称'
            }
            ]"
            dataListUrl="/epc/contractmajor/contractMajor/list"
            entityBeanName="contractMajor"
            queryEntityUrl="/epc/contractmajor/contractMajor/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="客户id" prop="client.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择客户id"
            labelName = 'clientName'
            labelValue = 'id'
            :value = "inputForm.client.id"
            :limit="1"
            @getValue='(value) => {inputForm.client.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'clientName',
              label: '客户名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'clientName',
              label: '客户名称'
            }
            ]"
            dataListUrl="/epc/contractclient/contractClient/list"
            entityBeanName="contractClient"
            queryEntityUrl="/epc/contractclient/contractClient/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工区域" prop="constructionRegion"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionRegion" placeholder="请填写施工区域"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计单位" prop="designOrganization"
                :rules="[
                 ]">
              <el-input v-model="inputForm.designOrganization" placeholder="请填写设计单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="建设单位项目经理" prop="constructionUnitProjectManager"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionUnitProjectManager" placeholder="请填写建设单位项目经理"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="联系电话" prop="phone"
                :rules="[
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="监理单位" prop="supervisingUnit"
                :rules="[
                 ]">
              <el-input v-model="inputForm.supervisingUnit" placeholder="请填写监理单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="监理单位负责人" prop="supervisingUnitPrincipal"
                :rules="[
                 ]">
              <el-input v-model="inputForm.supervisingUnitPrincipal" placeholder="请填写监理单位负责人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记时间" prop="registrationTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.registrationTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登记人" prop="registrant"
                :rules="[
                 ]">
              <el-input v-model="inputForm.registrant" placeholder="请填写登记人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="设计人员" prop="designer"
                :rules="[
                 ]">
              <el-input v-model="inputForm.designer" placeholder="请填写设计人员"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程状态" prop="projectStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.projectStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('project_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="主要工程量" prop="majorWorks"
                :rules="[
                 ]">
              <el-input v-model="inputForm.majorWorks" placeholder="请填写主要工程量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工进度" prop="constructionProgress"
                :rules="[
                 ]">
              <el-input v-model="inputForm.constructionProgress" placeholder="请填写施工进度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="总体进度" prop="overallProgress"
                :rules="[
                 ]">
              <el-input v-model="inputForm.overallProgress" placeholder="请填写总体进度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="归档编号" prop="fileNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.fileNumber" placeholder="请填写归档编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="财务特批" prop="notarizedFinancial"
                :rules="[
                 ]">
              <el-input v-model="inputForm.notarizedFinancial" placeholder="请填写财务特批"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          jobNumber: '',
          contractAmount: '',
          singleName: '',
          settlementProperties: '',
          onstreamTime: '',
          completionTime: '',
          natureEngineeringConstruction: '',
          natureEngineeringSource: '',
          singleProject: '',
          managementFeeCategory: '',
          projectType: '',
          major: {
            id: ''
          },
          client: {
            id: ''
          },
          constructionRegion: '',
          designOrganization: '',
          constructionUnitProjectManager: '',
          phone: '',
          supervisingUnit: '',
          supervisingUnitPrincipal: '',
          registrationTime: '',
          registrant: '',
          designer: '',
          projectStatus: '',
          majorWorks: '',
          constructionProgress: '',
          overallProgress: '',
          fileNumber: '',
          notarizedFinancial: '',
          remarks: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建劳务合同工程信息`
        } else if (method === 'edit') {
          this.title = '修改劳务合同工程信息'
        } else if (method === 'view') {
          this.title = '查看劳务合同工程信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/epc/contractlabourinfo/contractLabourInfo/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.contractLabourInfo)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/epc/contractlabourinfo/contractLabourInfo/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>